<?php
namespace Admin\Controller;

use Common\Controller\AdminBaseController;

class MenuController extends AdminBaseController{
    /**
     * 展示菜单列表
     */
    public function index(){
        $menu = D('menu') -> menuList(0,'id,pid,title,ico,link,sort,status','sort');
        $menu = getTree($menu,0,0,'---');
        $this -> assign('list',$menu);
        $this -> display();
    }

    /**
     * 保存/修改菜单
     */
    public function save(){
        if(IS_POST){
            $this -> ajaxReturn(D('menu') -> addMenu(I('post.')));
        }
    }

    /**
     * 删除菜单
     */
    public function menuDel(){
        if(IS_POST){
            $id = I('post.id/d',0);
            $result = D('menu') -> menuDel($id);
            if($result){
                $this -> ajaxReturn($result);
            }
        }
    }

    /**
     * 修改菜单状态
     */
    public function menuChange(){
        if(IS_POST){
            $id = I('post.id/d',0);
            $result = D('menu') -> changeState($id);
            if($result){
                $this->ajaxReturn($result);
            }
        }
    }

    public function getData(){
        if(IS_POST){
            $id = I('post.id/d',0);
            $result = D('menu') -> getInfo($id);
            if($result){
                $this->ajaxReturn($result);
            }
        }
    }
}